找传奇、传世资源到传世资源站!

表示业务统计的图表控件

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

<br /><br /><p></p><p><pre class="brush:csharp;">using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Drawing;using ZedGraph;using ZedGraph.Web;using System.Collections.Generic;namespace Zegraph{ /**/ /// &lt;summary&gt; /// 显示统计图形类型 /// &lt;/summary&gt; public enum AnalyticsType { Line, //折线图 Bar, //柱状图 Pie //饼图 }; public partial class DrawGrap : System.Web.UI.UserControl { #region Private Attribute /**/ /// &lt;summary&gt; /// 默认颜色种类 /// &lt;/summary&gt; private List&lt;Color&gt; defaultColors = new List&lt;Color&gt;(); /**/ /// &lt;summary&gt; /// 统计的个数 /// &lt;/summary&gt; private int Count; #endregion #region Public Property /**/ /// &lt;summary&gt; /// 统计图的名称 /// &lt;/summary&gt; public string Title; /**/ /// &lt;summary&gt; /// 横轴的名称(饼图不需要) /// &lt;/summary&gt; public string XAxisTitle; /**/ /// &lt;summary&gt; /// 纵轴的名称(饼图不需要) /// &lt;/summary&gt; public string YAxisTitle; /**/ /// &lt;summary&gt; /// 显示的曲线类型:Line,Bar,Pie /// &lt;/summary&gt; public AnalyticsType Type; /**/ /// &lt;summary&gt; /// 折线图和柱状图的数据源 /// &lt;/summary&gt; public List&lt;PointPairList&gt; DataSource = new List&lt;PointPairList&gt;(); /**/ /// &lt;summary&gt; /// 饼图的数据源 /// &lt;/summary&gt; public List&lt;double&gt; ScaleData = new List&lt;double&gt;(); /**/ /// &lt;summary&gt; /// 各段数据的颜色 /// &lt;/summary&gt; public List&lt;Color&gt; Colors = new List&lt;Color&gt;(); /**/ /// &lt;summary&gt; /// 各段数据的名称 /// &lt;/summary&gt; public List&lt;string&gt; NameList = new List&lt;string&gt;(); /**/ /// &lt;summary&gt; /// 用于柱状图,每个圆柱体表示的含义 /// &lt;/summary&gt; public List&lt;string&gt; LabelList = new List&lt;string&gt;(); #endregion protected void Page_Load(object sender, EventArgs e) { zedGraphControl.RenderGraph = new ZedGraph.Web.ZedGraphWebControlEventHandler(zedGraphControl_RenderGraph); } private void InitDefaultColors() { defaultColors.Add(Color.Red); defaultColors.Add(Color.Green); defaultColors.Add(Color.Blue); defaultColors.Add(Color.Yellow); defaultColors.Add(Color.YellowGreen); defaultColors.Add(Color.Brown); defaultColors.Add(Color.Aqua); defaultColors.Add(Color.Cyan); defaultColors.Add(Color.DarkSeaGreen); defaultColors.Add(Color.Indigo); } /**/ /// &lt;summary&gt; /// 如果属性为空则初始化属性数据 /// &lt;/summary&gt; private void InitProperty() { InitDefaultColors(); if (string.IsNullOrEmpty(Title)) { Title = "未命名统计图"; } if (string.IsNullOrEmpty(XAxisTitle)) { XAxisTitle = "横轴"; } if (string.IsNullOrEmpty(YAxisTitle)) { YAxisTitle = "纵轴"; } if (Type == AnalyticsType.Pie) { Count = ScaleData.Count; } else { Count = DataSource.Count; } if (Colors.Count == 0 || Colors.Count != Count) { Random r = new Random(); int tempIndex = 0; List&lt;int&gt; tempIndexList = new List&lt;int&gt;(); for (int i = 0; i &lt; Count; i ) { tempIndex = r.Next(defaultColors.Count); if (tempIndexList.Contains(tempIndex)) { i--; } else { tempIndexList.Add(tempIndex); Colors.Add(defaultColors[tempIndex]); } } } if (NameList.Count == 0) { if (Type == AnalyticsType.Bar) { for (int i = 0; i &lt; DataSource[0].Count; i ) { NameList.Add("第" i.ToString() "组"); } } else { for (int i = 0; i &lt; Count; i ) { NameList.Add("第" i.ToString() "组"); } } } if (LabelList.Count == 0) { for (int i = 0; i &lt; Count; i ) { LabelList.Add("含义" i.ToString()); } } } /**/ /// &lt;summary&gt; /// 画图51-a-s-px /// &lt;/summary&gt; /// &lt;param name="webObject"&gt;&lt;/param&gt; /// &lt;param name="g"&gt;&lt;/param&gt; /// &lt;param name="pane"&gt;&lt;/param&gt; private void zedGraphControl_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane) { InitProperty(); GraphPane myPane = pane[0]; myPane.Title.Text = Title; myPane.XAxis.Title.Text = XAxisTitle; myPane.YAxis.Title.Text = YAxisTitle; switch (Type) { case AnalyticsType.Line: DrawLine(myPane); break; case AnalyticsType.Bar: DrawBar(myPane); break; case AnalyticsType.Pie: DrawPie(myPane); break; default: break; } pane.AxisChange(g); } #region Draw /**/ /// &lt;summary&gt; /// 画折线图 /// &lt;/summary&gt; /// &lt;param name="graphPane"&gt;&lt;/param&gt; private void DrawLine(GraphPane graphPane) { for (int i = 0; i &lt; Count; i ) { graphPane.AddCurve(NameList[i], DataSource[i], Colors[i], SymbolType.None); } } /**/ /// &lt;summary&gt; /// 画柱状图 /// &lt;/summary&gt; /// &lt;param name="graphPane"&gt;&lt;/param&gt; private void DrawBar(GraphPane graphPane) { for (int i = 0; i &lt; Count; i ) { graphPane.AddBar(LabelList[i], DataSource[i], Colors[i]).Bar.Fill = new Fill(Colors[i], Color.White, Colors[i]); } graphPane.XAxis.MajorTic.IsBetweenLabels = true; string[] labels = NameList.ToArray(); graphPane.XAxis.Scale.TextLabels = labels; graphPane.XAxis.Type = AxisType.Text; graphPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); graphPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); } /**/ /// &lt;summary&gt; /// 画饼图 /// &lt;/summary&gt; /// &lt;param name="graphPane"&gt;&lt;/param&gt; private void DrawPie(GraphPane graphPane) { graphPane.Fill = new Fill(Color.White, Color.Silver, 45.0f); graphPane.Legend.Position = LegendPos.Float; graphPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top); graphPane.Legend.FontSpec.Size = 20f; graphPane.Legend.IsHStack = false; for (int i = 0; i &lt; Count; i ) { graphPane.AddPieSlice(ScaleData[i], Colors[i], Color.White, 45f, 0, NameList[i]); } } /**/ /// &lt;summary&gt; /// 如果系统出错,显示错误信息 /// &lt;/summary&gt; /// &lt;param name="graphPane"&gt;&lt;/param&gt; /// &lt;param name="message"&gt;&lt;/param&gt; private void DrawMessage(GraphPane graphPane, string message) { TextObj text = new TextObj(message, 200, 200); text.Text = message; graphPane.GraphObjList.Add(text); } #endregion }}</pre></p><p><br /></p>

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复